using System;
using System.Windows.Forms;
using System.Text;

namespace RedBlueBalls
{
    /// <summary>
    /// A class to write trace message
    /// </summary>
    class Tracer
    {
        private static bool _started = false;
        private static StringBuilder _builder;
        private static TextBox _textBox;

        public static void SetTracer(TextBox textBox)
        {
            _textBox = textBox;
        }

        /// <summary>
        /// Append a new message to output cache
        /// </summary>
        /// <param name="message"></param>
        public static void AppendMessage(string message)
        {
            if (!_started)
            {
                _builder = new StringBuilder(_textBox.Text);
                _started = true;
            }

            _builder.AppendLine(message);
        }

        /// <summary>
        /// Show message on output
        /// </summary>
        public static void ShowMessage()
        {
            if (_started)
            {
                _textBox.Text = _builder.ToString();
                _started = false;
            }
        }
    }
}
